<template>
  <div class="cs-page-container">
    <el-tabs value="third" type="border-card" @tab-click="handleClick">
      <el-tab-pane label="提现列表" name="first" />
      <el-tab-pane label="已提现列表" name="second" />
      <el-tab-pane label="拒绝提现列表" name="third" />

      <div class="cs-filter-container">
        <el-input
          v-model="listQuery.userId"
          clearable
          placeholder="请输入用户ID"
        />
        <el-select
          v-model="listQuery.withdrawType"
          clearable
          placeholder="提现方式"
          style="width:100px"
        >
          <el-option
            v-for="(option, key , index) in payTypeItem"
            :key="index"
            :label="option"
            :value="key"
          />
        </el-select>
        <el-select
          v-model="listQuery.countryCode"
          clearable
          filterable
          placeholder="国家"
          style="width:100px"
        >
          <el-option
            v-for="(value, key, index) in countryCodeItem"
            :key="index"
            :label="value"
            :value="key"
          />
        </el-select>
        <el-date-picker
          v-model="daterangeValue"
          :picker-options="daterangePickerOptions"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="创建起始时间"
          end-placeholder="创建结束时间"
          value-format="yyyy/MM/dd"
          @change="daterangeChanged"
        />
        <el-button
          type="primary"
          size="small"
          icon="el-icon-search"
          @click="handleFilter"
        >搜索</el-button>
        <el-button
          type="info"
          size="small"
          icon="el-icon-refresh-right"
          @click="handleResetFilter"
        >重置</el-button>
      </div>
      <div class="cs-filter-result">
        <el-table
          :key="tableKey"
          v-loading="listLoading"
          :data="list"
          :height="'calc(100vh - 300px)'"
          border
          fit
          highlight-current-row
          style="width: 100%;"
        >
          <el-table-column
            label="提现日期"
            prop="applyTime"
            align="center"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.applyTime | parseTime }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="最后操作时间"
            prop="updateTime"
            align="center"
            width="180"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.updateTime | parseTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="提现ID" align="center" prop="withDrawId" />
          <el-table-column label="用户ID" align="center">
            <template slot-scope="{ row }">
              <TooptipsCom :user-id="row.userId" />
            </template>
          </el-table-column>
          <el-table-column label="用户昵称" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.nickname }}</span>
            </template>
          </el-table-column>

          <el-table-column label="认证状态" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.identifyType | identify }}</span>
            </template>
          </el-table-column>
          <el-table-column label="封禁状态" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.forbiddenState | forbidden }}</span>
            </template>
          </el-table-column>
          <el-table-column label="点播视频违规(近三天)" align="center" width="130">
            <template v-if="scope.row.illegalInfo" slot-scope="scope">
              <span>违规次数: {{ scope.row.illegalInfo.demand }}<br>监控开启次数: {{ scope.row.illegalInfo.demandMonitoring }}<br>监控关闭次数: {{ scope.row.illegalInfo.demand - scope.row.illegalInfo.demandMonitoring }}<br></span>
            </template>
          </el-table-column>
          <el-table-column label="随机视频违规(近三天)" align="center" width="130">
            <template v-if="scope.row.illegalInfo" slot-scope="scope">
              <span>违规次数: {{ scope.row.illegalInfo.random }}<br>监控开启次数: {{ scope.row.illegalInfo.randomMonitoring }}<br>监控关闭次数: {{ scope.row.illegalInfo.random - scope.row.illegalInfo.randomMonitoring }}<br></span>
            </template>
          </el-table-column>
          <el-table-column label="提现方式" align="center">
            <template slot-scope="scope">
              <span>{{ payType[scope.row.type] }}</span>
            </template>
          </el-table-column>
          <el-table-column label="累计提现金额" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.totalWithdrawAmount / 10000 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="本次提现金额" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.amount / 10000 }} {{ payAmount[scope.row.type] }}</span>
            </template>
          </el-table-column>
          <el-table-column label="订单ID" align="center" prop="alipayOrderId" />
          <el-table-column label="当前状态" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.status | filterType }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="国家" width="130">
            <template slot-scope="{ row }">{{ row.countryCode | countryCode }}</template>
          </el-table-column>
          <el-table-column label="处理原因" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.dealReason }}</span>
            </template>
          </el-table-column>
          <el-table-column label="拒绝理由" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.refuseReason }}</span>
            </template>
          </el-table-column>
        </el-table>
        <TablePagination
          :current-page="listQuery.page"
          :limit="listQuery.limit"
          :total="total"
          :loading="listLoading"
          @handleSizeChange="handleSizeChange"
          @handleCurrentChange="handleCurrentChange"
        />
      </div>
    </el-tabs>
  </div>
</template>

<script>
  import TablePagination from '@/components/TablePagination' // secondary package based on el-pagination
  import { getWithdrawList } from '@/api/withdraw'
  import { getCountryItem } from '@/filters'

  export default {
    name: 'RefuseFinancial',
    components: { TablePagination },
    filters: {
      filterType(type) {
        switch (type) {
          case 0:
            return '待审核'
          case 1:
            return '提现失败'
          case 2:
            return '提现成功'
          case 3:
            return '拒绝提现'
          default:
            return '未知类型'
        }
      },
      identify(key) {
        const obj = {
          0: '未认证',
          1: '真人认证',
          2: '主播认证'
        }
        return obj[key]
      },
      forbidden(key) {
        const obj = {
          0: '正常',
          1: '封禁'
        }
        return obj[key]
      }
    },
    data() {
      return {
        tableKey: 0,
        list: null,
        total: 0,
        listLoading: true,
        defaultQueryParams: {},
        listQuery: {
          page: 1,
          limit: 20,
          status: 3,
          startTime: null,
          endTime: null,
          userId: null
        },
        payType: {
          0: '支付宝',
          1: '微信',
          2: 'paypal'
        },
        payAmount: {
          0: '元',
          1: '元',
          2: '美元'
        },
        countryCodeItem: getCountryItem(),
        daterangeValue: ''
      }
    },
    created() {
      this.doSearch()
    },
    methods: {
      handleResetFilter() {
        this.defaultQueryParams = Object.assign(
          {},
          {
            page: 1,
            limit: 20,
            status: 3,
            startTime: null,
            endTime: null,
            userId: null
          }
        )
        this.resetFilter()
      },
      doSearch() {
        this.listLoading = true
        getWithdrawList(this.listQuery).then(response => {
          this.list = response.data.userWithdrawList
          this.total = response.data.total
          this.listLoading = false
        })
      },
      handleClick(tab) {
        switch (tab.name) {
          case 'second':
            this.$router.push('/anchor/withdraw-resolve')
            break
          case 'first':
            this.$router.push('/anchor/withdraw-list')
            break
        }
      }
    }
  }
</script>
